<template>
  <div class="sidebar">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157" text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template #title>
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                <template #title>{{ subItem.title }}</template>
                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{
                  threeItem.title
                }}</el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
// import bus from "../common/bus";
export default {
  data() {
    return {
      items: [
        { icon: "el-icon-lx-home", index: "dashboard", title: "系统首页" },
        {
          icon: "el-icon-lx-settings",
          index: "1",
          title: "系统管理",
          subs: [
            { index: "advertPic", title: "广告图片" },
            { index: "usersMessage", title: "公告信息中心" },
            { index: "appConfig", title: "APP配置" },
            { index: "sysConfig", title: "系统配置" },
            { index: "dayTask", title: "任务配置" }
          ]
        },
        {
          icon: "el-icon-lx-group",
          index: "2",
          title: "用户管理",
          subs: [
            { index: "userControl", title: "用户管理", },
            { index: "powerAudit", title: "商家审核", },
            { index: "authentication", title: "实名认证审核", }
          ]
        },
        {
          icon: "el-icon-lx-crown",
          index: "q2",
          title: "等级管理",
          subs: [
            { index: "usersMemberConfig", title: "VIP等级配置", },
            { index: "usersTeamConfig", title: "团队等级配置", },
            { index: "usersTierConfig", title: "合伙人等级配置", }
          ]
        },
        {
          icon: "el-icon-lx-shop",
          index: "3",
          title: "门店管理",
          subs: [
            { index: "store", title: "门店管理", },
            { index: "storeClass", title: "门店分类", },
            { index: "storeOrder", title: "商家订单管理", }
          ]
        },

        {
          icon: "el-icon-lx-goods",
          index: "8",
          title: "自营商城",
          subs: [
            { index: "zyMallClass", title: "自营商城分类", },
            { index: "zyMallCommodity", title: "自营商城商品", },
            { index: "zyMallOrder", title: "自营商城订单", },
            { index: "zyMallPartition", title: "自营分区", },
            { index: "zyMallRefund", title: "自营商城退款", },
            { index: "freight", title: "运费模板", }
          ]
        },
        {
          icon: "el-icon-lx-tag",
          index: "9",
          title: "释放管理",
          subs: [
            { index: "/releaseConfig", title: "释放配置", },
            { index: "/releaseOrder", title: "释放订单", },
            { index: "/releaseRecord", title: "释放记录", }
          ],
        },
        {
          icon: "el-icon-lx-recharge",
          index: "5",
          title: "数字资产",
          subs: [
            { index: "daConfig", title: "数字资产配置", },
            { index: "daLink", title: "数字资产链信息", },
            {
              title: "资金明细",
              index: "51",
              subs: [
                { index: "cyBer", title: "资金明细" },
                { index: "recharge", title: "资金充值审核" },
                { index: "withdraw", title: "资金提现审核" }
              ]
            }
          ]
        },
      ],
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", "");
    },
    collapse() {
      return this.$store.state.collapse;
    },
  },
  created() {
    switch (localStorage.getItem("ms_username")) {
      case 'order':
        this.items = [{
          icon: "el-icon-lx-goods",
          index: "8",
          title: "自营商城",
          subs: [{ index: "zyMallCommodity", title: "自营商城商品", }, { index: "zyMallOrder", title: "自营商城订单", }, { index: "zyMallRefund", title: "自营商城退款", }]
        }, {
          icon: "el-icon-present",
          index: "flashKillOrder",
          title: "秒杀订单",
        }, {
          icon: "el-icon-present",
          index: "lotteryOrder",
          title: "幸运大转盘订单"
        }, {
          icon: "el-icon-present",
          index: "blindOrder",
          title: "盲盒订单",
        }]
        break;
      case 'meigong':
        this.items = [{
          icon: "el-icon-lx-goods",
          index: "zyMallCommodity",
          title: "自营商城商品",
        }]
        break;
    }
  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}

.sidebar > ul {
  height: 100%;
}
</style>
